#pragma once
#include <functional>
#include "Common.hpp"
#include "Socket.hpp"
#include "InetAddr.hpp"
#include "Protocol.hpp"
#include "Connection.hpp"
#include "NetCal.hpp"
using namespace sock_ns;

class PackpageParse
{
public:
    void Excute(Connection *con) // 执行IO交互
    {
        std::string packagestream;
        while (true)
        {
            // 确定报文是否完整？
            std::string package = Decode(packagestream);
            if (package.empty())
                break; // 如果不是完整的报文就重新读取

            auto res = Factor::BuildRequestDefault();
            // 对client发过来的请求进行反序列化
            res->Deserialization(package);
            // 业务处理
            auto resp = _cal.CalWork();// 发出请求，接收一个回应
            std::string res_package;

            //  对返回的应答进行序列化
            // resp->Serialization(&res_package);

            // 形成完整报文
            std::string resjson = Encode(res_package);
        }
    }

private:
    NetCal _cal;
};
